package demo1.web.servlet.userMaiapi;

import demo1.dao.Mapper.userMaiMapper;
import demo1.pojo.userMai;
import demo1.dao.sql.userMaisql;
import demo1.service.userMaiService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/userMaiModifypop")
public class userMaiModifypop extends HttpServlet {//修改商户的信息
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("utf-8");
        String username = req.getParameter("username");
        String userAddress = req.getParameter("userAddress");
        String userDo = req.getParameter("userDo");
        resp.setContentType("text/html;charset = utf-8");
        HttpSession session = req.getSession();
        Object userObject = session.getAttribute("users");
            userMai users = (userMai) userObject;
            users.setUserDo(userDo);
            users.setUserAddress(userAddress);
            users.setUsername(username);

        userMaiService update = new userMaiService();
        try {
            update.updateUserMaiName(username, users.getId());
            update.updateUserMaiAddress(userAddress, users.getId());
            update.updateUserMaiDo(userDo, users.getId());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        resp.sendRedirect("/logindemo2/showUserMai.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
